Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@octokit/plugin-retry
Advanced tools
The @octokit/plugin-retry npm package is designed to automatically retry failed requests in Octokit, which is a set of client libraries for accessing GitHub's API. This plugin is particularly useful for handling transient errors and rate limit exceedances, improving the robustness of applications that interact with GitHub's API.
Automatic Retry on Failure
This feature automatically retries requests that fail due to server errors or rate limiting. The code sample shows how to integrate the retry plugin with Octokit and make a request that will be retried automatically in case of failure.
{
const { Octokit } = require('@octokit/core');
const { retry } = require('@octokit/plugin-retry');
const MyOctokit = Octokit.plugin(retry);
const octokit = new MyOctokit({ auth: 'personal-access-token' });
octokit.request('GET /repos/{owner}/{repo}', {
owner: 'octocat',
repo: 'hello-world'
}).catch(error => {
console.error('Request failed:', error);
});
}
axios-retry is a library that adds a retry feature to axios, a popular HTTP client. Similar to @octokit/plugin-retry, it helps in handling transient network errors by retrying failed requests. However, axios-retry is generic and can be used with any axios request, whereas @octokit/plugin-retry is specifically tailored for Octokit and GitHub API interactions.
fetch-retry extends the fetch API to support retries in a similar manner to @octokit/plugin-retry. It allows configuring retry count, retry delay, and retry on specific HTTP methods or status codes. Unlike @octokit/plugin-retry, which is designed for Octokit and GitHub API, fetch-retry can be used with any fetch-based requests, making it more versatile for different APIs.
Retries requests for server 4xx/5xx responses except
400
,401
,403
,404
, and422
.
Browsers |
Load
|
---|---|
Node |
Install with
|
const MyOctokit = Octokit.plugin(retry);
const octokit = new MyOctokit({ auth: "secret123" });
// retries request up to 3 times in case of a 500 response
octokit.request("/").catch((error) => {
if (error.request.request.retryCount) {
console.log(
`request failed after ${error.request.request.retryCount} retries`
);
}
console.error(error);
});
To override the default doNotRetry
list:
const octokit = new MyOctokit({
auth: "secret123",
retry: {
doNotRetry: [
/* List of HTTP 4xx/5xx status codes */
],
},
});
To override the number of retries:
const octokit = new MyOctokit({
auth: "secret123",
request: { retries: 1 },
});
You can manually ask for retries for any request by passing { request: { retries: numRetries, retryAfter: delayInSeconds }}
. Note that the doNotRetry
option from the constructor is ignored in this case, requests will be retried no matter their response code.
octokit
.request("/", { request: { retries: 1, retryAfter: 1 } })
.catch((error) => {
if (error.request.request.retryCount) {
console.log(
`request failed after ${error.request.request.retryCount} retries`
);
}
console.error(error);
});
Pass { retry: { enabled: false } }
to disable this plugin.
See CONTRIBUTING.md
FAQs
Automatic retry plugin for octokit
The npm package @octokit/plugin-retry receives a total of 1,879,572 weekly downloads. As such, @octokit/plugin-retry popularity was classified as popular.
We found that @octokit/plugin-retry demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.